<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>编辑</title>
	<link rel="stylesheet" type="text/css" href="../../plugins/layui/css/layui.css" />
	<link href="../../kitAdmin/css/app.css" rel="stylesheet" type="text/css" />
	<link rel="stylesheet" type="text/css" href="../../plugins/select2/dist/css/select2.min.css"/>
	<style type="text/css">
		/* .select2-container{
            display:none;
        } */

		.layui-unselect.layui-form-select {
			display: none;
		}
	</style>
</head>

<body>
<div class='kit-table'>
	<div style='margin:10px'>

		<form class='layui-form' action='' lay-filter='form-edit'>
			<input type='hidden' name='studentId'  data-link='{:studentId}' />
			<input type='hidden' name='istrylisten'  data-link='{:istrylistend}' />
			<div class='layui-form-item'>
				<div class='layui-inline'>
					<label class='layui-form-label'>手机号</label>
					<div class='layui-input-inline'>
						<input type='text' placeholder=''data-link='{:phone}' id='phone' name='phone' class='layui-input'>
					</div>
				</div>

                <div class='layui-inline' style="margin-top: 20px;">
                    <label class='layui-form-label'>姓名</label>
                    <div class='layui-input-inline'>
                        <input type='text' placeholder=''data-link='{:enName}' id='enName' name='enName' class='layui-input'>
                    </div>
                </div>

				<div class='layui-inline'  style="margin-top: 20px;">
					<label class='layui-form-label'>年龄</label>
					<div class='layui-input-inline'>
						<select placeholder=''data-link='{:age}' id='age' name='age' class='layui-input'>
                            <option value="4">4岁</option>
                            <option value="5">5岁</option>
                            <option value="6">6岁</option>
                            <option value="7">7岁</option>
                            <option value="8">8岁</option>
                            <option value="9">9岁</option>
                            <option value="10">10岁</option>
                            <option value="11">11岁</option>
                            <option value="12">12岁</option>
                            <option value="13">13岁</option>
                            <option value="14">14岁</option>
                            <option value="15">15岁</option>
                            <option value="16">16岁</option>
                        </select>
					</div>
				</div>
			</div>
		</form>
	</div>
</div>
<script src="../../common/js/jquery.js" type="text/javascript" charset="utf-8"></script>
<script src="../../static/js/base.js" type="text/javascript" charset="utf-8"></script>
<script src="../../plugins/jsviews/jsviews.js" type="text/javascript"></script>
<script src="../../plugins/layui/layui.js" type="text/javascript" charset="utf-8"></script>
<script src="../../plugins/select2/dist/js/select2.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
    var uid = getQueryVariable('studentId');

    var entity;

    var callback_save=function(){
        console.log($('.layui-form').serialize());
        return $('.layui-form').serialize();
    }

    function bindFormData(){
        if(uid){
            $.ajax({
                url:baseUrl+'/students/'+uid,
                type:'get',
                //async:false,
                success:function(data){
                    entity=data.data;
                    bindEnglishAbility();
                    bindLessonLevelSelect2();
                    $.link(true, ".kit-table", data.data);
                    $('select').select2().change();
                    //console.log(data.data.istrylisten);

                    $('input[name="istrylisten"]').val("是");
                },
                error:function(){
                    parent.layer.alert('系统或网络错误！');
                }
            });
        }
    }


    $(document).ready(function(){

        bindFormData();
        bindSexSelect2();
//				bindTeacherSelect2();
//				bindRecommendSelect2();
        bindFuzerenSelect2();
//				bindLessonSelect2();





        //select2通过模板绑定值以后不会自动刷新，需手动刷新一下；
        //注意，layui的select和select2用的不是一个控件，如果使用layui的select下面的这句可以注释掉
        //如果是select2，这下面的需要保留
        $('select').select2().change();

        $('#_cource').on("select2:select",function(){
            $('#_courceLevel').empty();
            $.ajax({
                url : baseUrl+"/levels/select2/" + $(this).val(),
                async : false,
                dataType : 'json',
                success : function(result) {

                    $('#_courceLevel').select2({
                        data : result
                    });

                }
            });
        });
        layui.use(['form'], function(){
            /* var form = layui.form;
            form.on('submit',function(){

            }) */
        });
    });

    function bindLessonLevelSelect2(data) {
        //console.log(entity);
        var courceData = [];
        $.ajax({
            type : "get",
            url : baseUrl+'/levels/select2/'+entity.cource,
            async : false,
            success : function(data) {
                //console.log(data);
                courceData = data;
                courceData.unshift({
                    id : '请选择',
                    text : '请选择'
                });
            }
        });

        $('#_courceLevel').select2({
            data : courceData
        });
    }

    function bindLessonSelect2() {
        var courceData = [];
        $.ajax({
            type : "get",
            url :baseUrl+ '/lessons/select2',
            async : false,
            success : function(data) {
                //console.log(data);
                courceData = data;
                courceData.unshift({
                    id : '请选择',
                    text : '请选择'
                });
            }
        });

        $('#_cource').select2({
            data : courceData
        });

    }

    function bindEnglishAbility() {
        var functional = entity.englishAbility;
        var groupCheckbox = $("input[name='englishAbility']");
        console.log('// 2018-9-25 chenbin: EnglishAbility:', functional);
        if (functional != null && functional != '') {
            // 2018-9-25 chenbin: 解决原数据无法绑定问题
            for (i = 0; i < groupCheckbox.length; i++) {
                var val = groupCheckbox[i].value;
                if (functional.split(',').indexOf(val) != -1) {
                    groupCheckbox[i].checked = true;
                }
            }
        }

    }

    function bindSexSelect2() {
        var sexData = [ {
            id : '请选择',
            text : '请选择'
        }, {
            id : '男',
            text : '男'
        }, {
            id : '女',
            text : '女'
        } ];

        $('#sex').select2({
            data : sexData
        });
    }

    function bindRecommendSelect2() {
        var courceData = [];
        $.ajax({
            type : "get",
            url :baseUrl+ '/students/select2',
            async : false,
            success : function(data) {
                //console.log(data);
                courceData = data;
                courceData.unshift({
                    id : '请选择',
                    text : '请选择'
                });
            }
        });

        $('#_recommend').select2({
            data : courceData
        });
    }
    function bindFuzerenSelect2() {
        var courceData = [];
        $.ajax({
            type : "get",
            url : baseUrl+'/admins/select2',
            async : false,
            success : function(data) {
                //console.log(data);
                courceData = data;
                courceData.unshift({
                    id : '请选择',
                    text : '请选择'
                });
            }
        });

        $('#_fuzerenId').select2({
            data : courceData
        });
    }
    function bindTeacherSelect2() {
        var courceData = [];
        $.ajax({
            type : "get",
            url :baseUrl+ '/teachers/select2',
            async : false,
            success : function(data) {
                //console.log(data);
                courceData = data;
                courceData.unshift({
                    id : '请选择',
                    text : '请选择'
                });
            }
        });

        $('#_teacherId').select2({
            data : courceData
        });
    }

    function setaudiotime(){
        var teacherid=$("#_teacherId").val();
        if(teacherid=="请选择"){
            alert("请选择老师");
            return;
        }
        var studentid=uid;
        console.log(uid);
        parent.layer.open({
            id:teacherid+'info',
            maxmin: true,
            type: 2,
            area: modalArea,
            content: './views/Period_Used.html?techerid='+teacherid+'&studentid='+uid,
            btn: ['保存', '取消'],
            yes: function(index, layero) {
                var data = $(layero).find("iframe")[0].contentWindow.callback_save();
                console.log(layero);
                $.ajax({
                    url:baseUrl+ '/teacherPeriods/periodUsed/save/'+data[0],
                    type: 'POST',
                    data: data[1],//,teacherId:'1245745'
                    dataType:"json",
                    contentType:"application/json",
                    success: function(data) {
                        /* alert(data.data); */
                        alert("保存成功");
                    }
                });
            },
            btn2: function(index, layero) {
                //按钮【按钮二】的回调
                console.log(layero);
                //return false 开启该代码可禁止点击该按钮关闭
            }
        });
    }

</script>
</body>

</html>
